<template>
	<view class="order tn-safe-area-inset-bottom">

		<!-- 顶部自定义导航 -->
		<tn-nav-bar :isBack="false" :bottomShadow="false" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<view class="custom-nav__back" @click="tn('/subpages/home/home/home')">
					<view class="tn-icon-home"></view>
				</view>
				<view class="" style="width: 62vw;overflow: hidden;margin-top: 36rpx;">
					<tn-tabs :list="scrollList" :current="current" @change="tabChange" activeColor="#000" :bold="true"
						:fontSize="36"></tn-tabs>
				</view>
			</view>
		</tn-nav-bar>

		<view class="tn-margin-top-sm" :style="{paddingTop: vuex_custom_bar_height - 10 + 'px'}">
			<swiper class="card-swiper" :circular="true" :autoplay="true" duration="500" interval="8000" @change="cardSwiper">
				<swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''"
					@click="tn(item.navigate)">
					<view class="swiper-item image-banner"
						:style="'background-image:url('+ item.image + ');background-size: cover;border-radius: 15rpx;'">
					</view>
					<view class="swiper-item-text">
						<view class="tn-text-bold tn-color-white" style="font-size: 50rpx;">{{item.first_title}}</view>
						<view class="tn-color-white tn-padding-top" style="font-size: 30rpx;">{{item.second_title}}</view>
						<view class="tn-text-sm tn-text-bold tn-color-white tn-padding-top-sm tn-padding-bottom-sm"></view>
					</view>
				</swiper-item>
			</swiper>
			<view class="indication">
				<block v-for="(item,index) in swiperList" :key="index">
					<view class="spot" :class="cardCur==index?'active':''"></view>
				</block>
			</view>
		</view>

		<view class="" v-if="collectionList.length > 0">
			<!-- 试题列表开始 -->
			<view class="tn-flex tn-flex-wrap tn-margin-sm">
				<block v-for="(item, index) in collectionList" :key="index">
					<view class="" style="width: 50%;" @click="tn('/subpages/exam/collection/detail?uid=' + item.uid)">
						<view class="tn-blogger-content__wrap">
							<view class="image-picbook" :style="'background-image:url(' + item.image + ')'">
								<view class="image-book">
								</view>
							</view>
							<view class="tn-blogger-content__label tn-text-justify tn-padding-sm">
								<text class="tn-blogger-content__label__desc">{{ item.title }}</text>
							</view>
							<view
								class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-left-sm tn-padding-right-sm tn-padding-bottom-sm">
								<view class="justify-content-item tn-text-center">
									<view v-if="item.level == 1"
										class="tn-blogger-content__label__item tn-float-left tn-margin-right tn-bg-gray--light tn-round tn-text-sm tn-text-bold">
										<text class="tn-blogger-content__label__item--prefix">#</text> 简单
									</view>
									<view v-if="item.level == 2"
										class="tn-blogger-content__label__item tn-float-left tn-margin-right tn-bg-gray--light tn-round tn-text-sm tn-text-bold">
										<text class="tn-blogger-content__label__item--prefix">#</text> 较难
									</view>
									<view v-if="item.level == 3"
										class="tn-blogger-content__label__item tn-float-left tn-margin-right tn-bg-gray--light tn-round tn-text-sm tn-text-bold">
										<text class="tn-blogger-content__label__item--prefix">#</text> 中等
									</view>
									<view v-if="item.level == 4"
										class="tn-blogger-content__label__item tn-float-left tn-margin-right tn-bg-gray--light tn-round tn-text-sm tn-text-bold">
										<text class="tn-blogger-content__label__item--prefix">#</text> 困难
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
			<!-- 试题列表结束 -->
			<tn-load-more :status="loadStatus"></tn-load-more>
		</view>

		<view class="" v-if="collectionList.length == 0">
			<view class="" style="padding: 15vh 20rpx;">
				<view class="tn-text-center" style="font-size: 200rpx;padding-top: 30rpx;">
					<text class="tn-icon-empty-page tn-color-gray--light"></text>
				</view>
				<view class="tn-color-gray--disabled tn-text-center tn-text-lg">试题正在努力添加中</view>
			</view>
		</view>

		<view class='tn-tabbar-height'></view>


	</view>
</template>

<script>
	import {
		getCollectionList
	} from "@/utils/api/exam.js"
	import {
		getBannerList,
	} from "@/utils/api/config.js"
	export default {
		name: 'Comm',
		data() {
			return {
				current: 0,
				scrollList: [{
						name: '推荐'
					},
					{
						name: '最新'
					},
					{
						name: '最热'
					}
				],
				cardCur: 0,
				swiperList: [], // 轮播图
				loadStatus: 'loading',
				collectionList: [],
				searchWhere: { // 试卷查询条件
					page: 1,
					size: 20,
					recommend: 1,
					hot: 0,
					least: 0,
				},
			}
		},
		onLoad() {

		},
		onShow() {
			this.getCollectionList()
			this.getBannerList()
		},
		methods: {
			// 获取试卷列表
			getCollectionList(type = 1) {
				uni.showLoading({
					title: "努力加载中",
					mask: true,
				})
				getCollectionList(this.searchWhere).then(res => {
					if (res.code == 100) {
						if (type == 2) {
							this.collectionList = []
						}
						this.collectionList.push(...res.data.items)
						this.searchWhere.page = res.data.page + 1
						console.log(this.collectionList.length, res.data.count)
						if (this.collectionList.length == res.data.count) {
							this.loadStatus = "nomore"
						} else {
							this.loadStatus = "loadmore"
						}
						uni.hideLoading()
						return
					}
					uni.hideLoading()
					this.$func.showToast(res.msg)
				})
			},
			// 轮播图
			getBannerList() {
				getBannerList({
					position: "mini_collection_home",
					platform: "wechat_mini",
				}).then(res => {
					if (res.code == 100) {
						this.swiperList = res.data
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 跳转
			tn(e) {
				this.$func.navigatorTo(e)
			},
			// cardSwiper
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			// 试题类型选项卡切换
			tabChange(index) {
				if (index == 0) {
					this.searchWhere.recommend = 1
					this.searchWhere.hot = 0
					this.searchWhere.least = 0
				} else if (index == 2) {
					this.searchWhere.recommend = 0
					this.searchWhere.hot = 1
					this.searchWhere.least = 0
				} else {
					this.searchWhere.recommend = 0
					this.searchWhere.hot = 0
					this.searchWhere.least = 1
				}
				this.current = index
				this.searchWhere.page = 1
				this.getCollectionList(2)
			},
		},
		onReachBottom() {
			this.getCollectionList()
		}
	}
</script>

<style lang="scss" scoped>
	.order {
		max-height: 100vh;
	}

	.collection-remark {
		font-size: 24rpx;
	}

	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin: auto 5rpx;
			font-size: 45rpx;
			margin-right: 10rpx;
			margin-left: 30rpx;
			flex-basis: 5%;
		}

		&__search {
			flex-basis: 60%;
			width: 100%;
			height: 100%;

			&__box {
				width: 100%;
				height: 70%;
				padding: 10rpx 0;
				margin: 0 30rpx;
				border-radius: 60rpx 60rpx 0 60rpx;
				font-size: 24rpx;
			}

			&__icon {
				padding-right: 10rpx;
				margin-left: 20rpx;
				font-size: 30rpx;
			}

			&__text {
				// color: #AAAAAA;
			}
		}
	}

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}

	/* 阴影 start*/
	.home-shadow {
		border-radius: 10rpx;
		box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0, 0, 0, 0.07);
	}


	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/* 轮播视觉差 start */
	.card-swiper {
		height: 400rpx !important;
	}

	.card-swiper swiper-item {
		width: 750rpx !important;
		left: 0rpx;
		box-sizing: border-box;
		padding: 40rpx 30rpx 30rpx 30rpx;
		overflow: initial;
	}

	.card-swiper swiper-item .swiper-item {
		width: 100%;
		display: block;
		height: 100%;
		border-radius: 10rpx;
		transform: scale(1);
		transition: all 0.2s ease-in 0s;
		will-change: transform;
		// overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item {
		transform: none;
		transition: all 0.2s ease-in 0s;
		will-change: transform;
	}

	.card-swiper swiper-item .swiper-item-text {
		margin-top: -160rpx;
		text-align: center;
		width: 100%;
		display: block;
		height: 50%;
		border-radius: 10rpx;
		transform: translate(100rpx, -60rpx) scale(0.9, 0.9);
		transition: all 0.6s ease 0s;
		will-change: transform;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item-text {
		margin-top: -220rpx;
		width: 100%;
		transform: translate(0rpx, 0rpx) scale(0.9, 0.9);
		transition: all 0.6s ease 0s;
		will-change: transform;
	}

	.image-banner {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.image-banner image {
		width: 100%;
		height: 100%;
	}

	/* 轮播指示点 start*/
	.indication {
		z-index: 9999;
		width: 100%;
		height: 36rpx;
		position: absolute;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.spot {
		background-color: #FFFFFF;
		opacity: 0.6;
		width: 10rpx;
		height: 10rpx;
		border-radius: 20rpx;
		top: -70rpx;
		margin: 0 8rpx !important;
		position: relative;
	}

	.spot.active {
		opacity: 1;
		width: 30rpx;
		background-color: #FFFFFF;
	}

	/* 标题 start */
	  .nav_title {
	    -webkit-background-clip: text;
	    color: transparent;
	    
	    &--wrap {
	      position: relative;
	      display: flex;
	      height: 120rpx;
	      font-size: 46rpx;
	      align-items: center;
	      justify-content: center;
	      font-weight: bold;
	      background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title44.png);
	      background-size: cover;
	    }
	  }
	  /* 标题 end */
	  
	  /* 文章内容 start*/
	  .tn-blogger-content {
	    &__wrap {
	      box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.12);
	      border-radius: 20rpx;
	      margin: 15rpx;
	    }
	    
	    &__info {
	      &__btn {
	        margin-right: -12rpx;
	        opacity: 0.5;
	      }
	    }
	    
	    &__label {
	      &__item {
	        line-height: 45rpx;
	        // padding: 0 20rpx;
	        margin: 5rpx 18rpx 0 0;
	        
	        &--prefix {
	          color: #E83A30;
	          padding-right: 10rpx;
	        }
	      }
	      
	      &__desc {
	        line-height: 35rpx;
	      }
	    }
	    
	    &__main-image {
	      border-radius: 16rpx 16rpx 0 0;
	      
	      &--1 {
	        max-width: 690rpx;
	        min-width: 690rpx;
	        max-height: 400rpx;
	        min-height: 400rpx;
	      }
	      
	      &--2 {
	        max-width: 260rpx;
	        max-height: 260rpx;
	      }
	      
	      &--3 {
	        height: 212rpx;
	        width: 100%;
	      }
	    }
	    
	    &__count-icon {
	      font-size: 30rpx;
	      padding-right: 5rpx;
	    }
	  }
	  
	  .image-book{
	    padding: 150rpx 0rpx;
	    font-size: 16rpx;
	    font-weight: 300;
	    position: relative;
	  }
	  .image-picbook{
	    background-size: cover;
	    background-repeat:no-repeat;
	    // background-attachment:fixed;
	    background-position:top;
	    border-radius: 20rpx 20rpx 0 0;
	  }
	  /* 文章内容 end*/
</style>